package com.ruoyi.fireman.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.fireman.domain.TImage;
import com.ruoyi.fireman.mapper.TImageMapper;
import com.ruoyi.fireman.service.ITImageService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 图片存储Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-08-28
 */
@Service
public class TImageServiceImpl extends ServiceImpl<TImageMapper, TImage>  implements ITImageService
{
    @Autowired
    private TImageMapper tImageMapper;

    /**
     * 查询图片存储
     * 
     * @param id 图片存储主键
     * @return 图片存储
     */
    @Override
    public TImage selectTImageById(Long id)
    {
        return tImageMapper.selectTImageById(id);
    }

    /**
     * 查询图片存储列表
     * 
     * @param tImage 图片存储
     * @return 图片存储
     */
    @Override
    public List<TImage> selectTImageList(TImage tImage)
    {
        return tImageMapper.selectTImageList(tImage);
    }

    /**
     * 新增图片存储
     * 
     * @param tImage 图片存储
     * @return 结果
     */
    @Override
    public int insertTImage(TImage tImage)
    {
        tImage.setCreateTime(DateUtils.getNowDate());
        return tImageMapper.insertTImage(tImage);
    }

    /**
     * 修改图片存储
     * 
     * @param tImage 图片存储
     * @return 结果
     */
    @Override
    public int updateTImage(TImage tImage)
    {
        return tImageMapper.updateTImage(tImage);
    }

    /**
     * 批量删除图片存储
     * 
     * @param ids 需要删除的图片存储主键
     * @return 结果
     */
    @Override
    public int deleteTImageByIds(String ids)
    {
        return tImageMapper.deleteFlagTImageByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除图片存储信息
     * 
     * @param id 图片存储主键
     * @return 结果
     */
    @Override
    public int deleteTImageById(Long id)
    {
        return tImageMapper.deleteTImageById(id);
    }

    @Override
    public int saveImageBatch(String name, String[] urls) {
        if (ObjectUtils.isNotEmpty(urls)) {
            for (String url : urls) {
                TImage image = new TImage();
                image.setName(name);
                image.setUrl(url);
                tImageMapper.insertTImage(image);
            }
            return urls.length;
        }
        return 0;
    }
}
